package com.cib.xagcjs.utils;

import com.cib.xagcjs.common.RmbRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * Description: 组装请求工具类
 * Author: jingcaiqi1225@gmail.com
 * Date: 2024/2/2 8:44
 */
@Slf4j
@Component
public class RequestUtil {
    /**
     * 获取组装报文方法
     * @return 组装后的报文
     */
    public RmbRequest getRequest(String function, ArrayList<Object> list) {

        // 构建 CtorMsg 对象
        RmbRequest.CtorMsg ctorMsg = new RmbRequest.CtorMsg();
        ctorMsg.setFunction(function);
        ctorMsg.setArgs(list);

        // 构建 Params 对象
        RmbRequest.Params params = new RmbRequest.Params();
        // 构建 ChaincodeID 对象
        RmbRequest.ChaincodeID chaincodeID = new RmbRequest.ChaincodeID();
        chaincodeID.setName("");
        params.setType(1);
        params.setChaincodeID(chaincodeID);
        params.setCtorMsg(ctorMsg);
        params.setSecureContext("");

        // 构建 UnifiedRequest 对象
        RmbRequest rmbRequest = new RmbRequest();
        rmbRequest.setJsonrpc("");
        rmbRequest.setMethod("");
        rmbRequest.setParams(params);
        rmbRequest.setId(5);
        rmbRequest.setMode("");

        // 使用 Jackson 将对象转换为 JSON 字符串
//        return JSONObject.toJSONString(unifiedRequest);
        return rmbRequest;
    }
}
